<template>
  <footer class="footer">
    <span class="todo-count">
      <span>剩余 {{ remaining }} 项</span>
    </span>
    <ul class="filters">
      <li>
        <a
          href="#/all"
          :class="{
            selected: visibility === 'all'
          }"
          >全部</a
        >
      </li>
      <li>
        <a
          href="#/active"
          :class="{
            selected: visibility === 'active'
          }"
          >未完成</a
        >
      </li>
      <li>
        <a
          href="#/completed"
          :class="{
            selected: visibility === 'completed'
          }"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="removeAllCompleted" v-show="todos.length > remaining">
      清除已完成
    </button>
  </footer>
</template>

<script setup>
// 接收父组件通过 v-model 传递过来的数据
const todos = defineModel('todos')
const remaining = defineModel('remaining')
const emits = defineEmits(['removeAll'])

function removeAllCompleted() {
  emits('removeAll')
}
</script>

<style scoped>
@import '../assets/common.css';
.footer {
  padding: 10px 15px;
  height: 20px;
  text-align: center;
  font-size: 15px;
  border-top: 1px solid #e6e6e6;
}

.footer:before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 50px;
  overflow: hidden;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.2),
    0 8px 0 -3px #f6f6f6,
    0 9px 1px -3px rgba(0, 0, 0, 0.2),
    0 16px 0 -6px #f6f6f6,
    0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
.todo-count {
  float: left;
  text-align: left;
}

.todo-count strong {
  font-weight: 300;
}

.filters {
  margin: 0;
  padding: 0;
  list-style: none;
  position: absolute;
  right: 0;
  left: 0;
}

.filters li {
  display: inline;
}

.filters li a {
  color: inherit;
  margin: 3px;
  padding: 3px 7px;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 3px;
}

.filters li a:hover {
  border-color: #db7676;
}

.filters li a.selected {
  border-color: #ce4646;
}
.clear-completed,
html .clear-completed:active {
  float: right;
  position: relative;
  line-height: 19px;
  text-decoration: none;
  cursor: pointer;
}

.clear-completed:hover {
  text-decoration: underline;
}
</style>
